<%@ page language="java" contentType="text/html; charset=utf-8" import="java.util.*"
         pageEncoding="utf-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Insert title here</title>
</head>
<body>
<%
    String cyu = request.getParameter("ciyu");
    int flag = 0;
    int ting = 0;
    if (cyu.length() != 12) {
        out.println("请输入正确的四字成语！" + "<br>");
        ting = 1;
    } else {
        //out.println("成语已经提交！"+"<br>");
        flag++;
    }


    String tou1 = request.getParameter("ciyu");
    String tou = request.getParameter("ciyu");
    String wei = request.getParameter("ciyu");
    String tag = "";
    String to = "";
    String we = "";
    String str = "";
    if (flag == 1) {
        tou1 = new String(tou1.getBytes("ISO-8859-1"), "utf-8");
        tag = tou1.substring(3);
//	out.println(tag);
        flag++;
    }

    if (flag > 1) {
        tou = new String(tou.getBytes("ISO-8859-1"), "utf-8");
        wei = new String(wei.getBytes("ISO-8859-1"), "utf-8");
        to = tou.substring(0, 1);
        we = wei.substring(3);
//    	out.println(to);
//    	out.println(we);
    }


    ArrayList mation = (ArrayList) session.getAttribute("mation");
    if (mation == null) {
        mation = new ArrayList();
        session.setAttribute("mation", mation);
    }
    String ciyu = request.getParameter("ciyu");
    if (ciyu != null && mation.size() > 0) {
        for (int i = 0; i < mation.size(); i++) {
            str = mation.get(i).toString();
            str = str.substring(3);
//			out.println(str);
        }
        if (str.equals(to)) {
            ciyu = new String(ciyu.getBytes("ISO-8859-1"), "utf-8");
            mation.add(ciyu);
            out.println("成语已经提交！" + "<br>");
        } else {
            out.println("成语首尾不匹配！");
        }
        if (str.equals(to)) {
            for (int i = 0; i < mation.size(); i++) {
                out.println(mation.get(i) + "-->");
            }
        }
    }
    if (ciyu != null && mation.size() == 0) {
        ciyu = new String(ciyu.getBytes("ISO-8859-1"), "utf-8");
        mation.add(ciyu);
        out.println("成语已经提交！" + "<br>");
        out.println(mation.get(0) + "-->");

    }
//	for(int i =0;i<mation.size();i++){
//		out.println(mation.get(i)+"-->");
//	}


%>
<br>
<a href="idiom.jsp">继续输入成语</a>
<%

%>
</body>
</html>